﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/Admin.Master" AutoEventWireup="true" CodeBehind="RoleList.aspx.cs" Inherits="SBACN.WebSite.Admin.Systems.RoleList" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
	<script type="text/javascript" src="/js/plugin/jquery.blockUI.js"></script>
	<script type="text/javascript">
		function GetRoleRight(roleID) {
			document.getElementById("<%= hid_RoleID.ClientID%>").value = roleID;
			$jqy.get("<%= RootPath%>Handler/Admin/RoleHandler.ashx?ri=" + roleID, function (data) {
				document.getElementById("<%= txt_Name.ClientID%>").value = data.RoleName;
				document.getElementById("<%= txt_Memo.ClientID%>").value = data.Description;
				var status = document.getElementById("<%= rbl_Status.ClientID%>").getElementsByTagName("input");
				for (var i = 0; i < status.length; i++) {
					if (status[i].type == "radio") {
						status[i].checked = (status[i].value == (data.Status.toString().toLowerCase() == "true" ? "1" : "0"));
					}
				}
			});
			$jqy.get("<%= RootPath%>Handler/Admin/RoleHandler.ashx?rid=" + roleID, function (data) {
				var radioList = document.getElementById("<%= td_RightList.ClientID%>").getElementsByTagName("input");
				for (var i = 0; i < radioList.length; i++) {
					if (radioList[i].type == "radio") {
						radioList[i].checked = false;
						if (radioList[i].id.indexOf("rb_N_") == 0)
							 radioList[i].checked = true
					}
				}
				if (data.length > 0) {
					for (var i = 0; i < data.length; i++) {
						if (document.getElementById("rb_W_" + data[i].Code)) {
							document.getElementById("rb_W_" + data[i].Code).checked = data[i].Type;
							document.getElementById("rb_R_" + data[i].Code).checked = !data[i].Type;
						}
					}
				}
				ShowBlock(false);
			});
		}

		function ShowBlock(reset) {
			$jqy.blockUI({
				message: document.getElementById('div_Content'),
				css: {
					top: '50%',
					left: '50%',
					textAlign: 'left',
					marginLeft: (-($jqy(document.getElementById('div_Content')).width() / 2)) + 'px',
					marginTop: (-($jqy(document.getElementById('div_Content')).height() / 1.9)) + 'px', 
					width: $jqy(document.getElementById('div_Content')).width() + 'px',
					hight: $jqy(document.getElementById('div_Content')).height() + 'px'
				}
			});
			if (reset) {
				document.getElementById("<%= hid_RoleID.ClientID%>").value = "";
				document.getElementById("<%= txt_Name.ClientID%>").value = "";
				document.getElementById("<%= txt_Memo.ClientID%>").value = "";
				document.getElementById("<%= lbl_Msg.ClientID%>").innerText = "";

				var status = document.getElementById("<%= rbl_Status.ClientID%>").getElementsByTagName("input");
				for (var i = 0; i < status.length; i++) {
					if (status[i].type == "radio") {
						status[i].checked = status[i].value == "0";
					}
				}

				var radioList = document.getElementById("<%= td_RightList.ClientID%>").getElementsByTagName("input");
				for (var i = 0; i < radioList.length; i++) {
					if (radioList[i].type == "radio") {
						radioList[i].checked = false; // radioList[i].value == "0";
						if (radioList[i].id.indexOf("rb_N_") == 0)
							radioList[i].checked = true
					}
				}
			}
		}

		function HideBlock() {
			$jqy.unblockUI();
		}
		function validInput() {
			if ($jqy.trim(document.getElementById("<%= txt_Name.ClientID%>").value).length == 0) {
				document.getElementById("<%= lbl_Msg.ClientID%>").innerText = "权限名称不能为空!";
				return false;
			}
			document.getElementById("<%= hid_RightList.ClientID%>").value = "";
			var radioList = document.getElementById("<%= td_RightList.ClientID%>").getElementsByTagName("input");
			for (var i = 0; i < radioList.length; i++) {
				if (radioList[i].type == "radio" && radioList[i].checked) {
					{
						if (radioList[i].id.indexOf("rb_W_") >= 0) {
							document.getElementById("<%= hid_RightList.ClientID%>").value += radioList[i].name + "|1;";
						}
						else if (radioList[i].id.indexOf("rb_R_") >= 0) {
							document.getElementById("<%= hid_RightList.ClientID%>").value += radioList[i].name + "|0;"
						}
					}
				}
			}
			$jqy("#div_Content").hide();
			document.getElementById("<%= lbl_Msg.ClientID%>").innerText = "";
			document.getElementById('form1').appendChild(document.getElementById('div_Content'));
			return true;
		}

		function ChangeRoleStatus(id) {
			document.getElementById("<%= hid_RoleID.ClientID%>").value = id;
			document.getElementById("<%= btn_Delete.ClientID%>").click();
		}
	</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
	<table width="100%" border="0" cellspacing="0" cellpadding="0" class="table-stroke2">
		<tr>
			<td class="form-title2">
				角色名称
			</td>
			<td class="form-title2">
				说明
			</td>
			<td class="form-title2">
				状态
			</td>
			<td class="form-title2">
				修改
			</td>
		</tr>
<asp:Repeater ID="rpt_Role" runat="server">
	<ItemTemplate>
		<tr>
			<td class="form-body" align="left">
				<%# Eval("Name")%>
			</td>
			<td class="form-body" align="left">
				<%# Eval("Description")%>
			</td>
			<td class="form-body">
				<%# Convert.ToBoolean(Eval("Status")) ? "启用" : "<font color='red'>停用</font>"%>
			</td>
			<td class="form-body">
				<a href="javascript:void(0)" onclick="return GetRoleRight('<%# Eval("ID")%>');">修改</a>&nbsp;&nbsp;<a style='visibility: <%# Convert.ToBoolean(Eval("Editable")) ? "visible" : "hidden" %>' href="javascript:void(0)" onclick="return ChangeRoleStatus('<%# Eval("ID")%>');"><%# Convert.ToBoolean(Eval("Status")) ? "停用" : "启用"%></a>
			</td>
		</tr>
	</ItemTemplate>
	<AlternatingItemTemplate>
		<tr>
			<td class="form-label" align="left">
				<%# Eval("Name")%>
			</td>
			<td class="form-label" align="left">
				<%# Eval("Description")%>
			</td>
			<td class="form-label">
				<%# Convert.ToBoolean(Eval("Status")) ? "启用" : "<font color='red'>停用</font>"%>
			</td>
			<td class="form-label">
				<a href="javascript:void(0)" onclick="return GetRoleRight('<%# Eval("ID")%>');">修改</a>&nbsp;&nbsp;<a style='visibility: <%# Convert.ToBoolean(Eval("Editable")) ? "visible" : "hidden" %>' href="javascript:void(0)" onclick="return ChangeRoleStatus('<%# Eval("ID")%>');"><%# Convert.ToBoolean(Eval("Status")) ? "停用" : "启用"%></a>
			</td>
		</tr>
	</AlternatingItemTemplate>
</asp:Repeater>
		<tr>
			<td colspan="4" class="form-body">
				
			</td>
		</tr>
		<tr>
			<td colspan="4" class="form-label">
				<input class ="btnsearch" type="button" value="新增" onclick="return ShowBlock(true);" />
			</td>
		</tr>
	</table>
	<div id="div_Content" style="display: none; padding:5px;">
		<table width="100%" border="0" cellspacing="0" cellpadding="0" class="table-stroke2">
			<tr>
				<td colspan="2" class="form-title2">
					角色管理
				</td>
			</tr>
			<tr>
				<td width="8%" class="form-label-1">
					角色名称:
				</td>
				<td class="form-body-1">
					<asp:TextBox ID="txt_Name" runat="server" Width="95%" MaxLength="50"></asp:TextBox><span style="color: Red">*</span>
				</td>
			</tr>
			<tr>
				<td width="8%" class="form-label-1">
					角色状态:
				</td>
				<td class="form-body-1">
					<asp:RadioButtonList ID="rbl_Status" runat="server" RepeatDirection="Horizontal" RepeatColumns="5">
						<asp:ListItem Text="启用" Value="1" Selected></asp:ListItem>
						<asp:ListItem Text="禁用" Value="0"></asp:ListItem>
					</asp:RadioButtonList>
				</td>
			</tr>
			<tr>
				<td width="8%" class="form-label-1">
					角色说明:
				</td>
				<td class="form-body-1">
					<asp:TextBox ID="txt_Memo" runat="server" Width="95%" MaxLength="200"></asp:TextBox>
				</td>
			</tr>
			<tr>
				<td class="form-body-1" id="td_RightList" colspan="2" valign="top" align="left" style="height: 330px;" runat="server" enableviewstate="false">
				</td>
			</tr>
			<tr>
				<td class="form-body" colspan="2" align="center" style="height: 28px;">
					<asp:Label ID="lbl_Msg" ForeColor="Red" runat="server">&nbsp;</asp:Label>
				</td>
			</tr>
			<tr>
				<td class="form-body" colspan="2" align="center" style="height: 35px;">
					<asp:Button ID="btn_Create" CssClass="btnsearch"  Text="确定" runat="server" OnClientClick="return validInput();" OnClick="btn_Create_Click" />&nbsp;
					<input type="button" value="取消" class="btnsearch" onclick="return HideBlock();" />
				</td>
			</tr>
		</table>
	</div>
	<div style="display:none;">
		<asp:HiddenField ID="hid_RoleID" runat="server" Value="" />
		<asp:HiddenField ID="hid_RightList" runat="server" Value="" />
		<asp:Button ID="btn_Delete" Text="删除" runat="server" OnClick="btn_Delete_Click" />
	</div>
	<script type="text/javascript">
		var accordionRight;
		var accordionTogglersRight;
		var accordionContentsRight;

		accordionTogglersRight = document.getElementsByClassName('rightTop');
		accordionTogglersRight.each(function (toggler) { });
		accordionContentsRight = document.getElementsByClassName('rightChild');
		accordionRight = new Fx.Accordion(accordionTogglersRight, accordionContentsRight, { onActive: function (toggler) { }, onBackground: function (toggler) { } });

		accordionRight.showThisHideOpen(-1);
	</script>
</asp:Content>
